package com.xiaoge.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.AbstractWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xiaoge.system.entity.Role;
import com.xiaoge.system.mapper.RoleMapper;
import com.xiaoge.system.service.RoleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * <p>
 * 角色表 服务实现类
 * </p>
 *
 * @author xiaoge
 * @since 2020-09-04
 */
@Service
public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements RoleService {


    public Long addRole(Role role){
        role.setCreateTime(new Date());
        this.baseMapper.insert(role);
        return role.getId();
    }

    /**
     * 模糊查询角色
     * @param roleName
     * @param remark
     * @return
     */
    public List<Role> queryByCondition(String roleName, String remark){
        AbstractWrapper wapper = new QueryWrapper();
        if(roleName !=null){
            wapper.like("role_name",roleName);
        }
        if (remark != null){
            wapper.like("remark",remark);
        }
        List<Role> list = this.baseMapper.selectList(wapper);
        return list;
    }

    /**
     * 删除方法
     * @return
     */
    public int delete(String id){
        int i = this.baseMapper.deleteById(id);
        return i;
    }

    /**
     * 修改方法
     */
    public int update(String id,Role role){
        role.setId(Long.valueOf(id));
        role.setModifiedTime(new Date());
        int i = this.baseMapper.updateById(role);
        return i;
    }
}
